// POJ 1159
#include <iostream>
#include <algorithm>
using namespace std;

int n;
char str[5009];

unsigned short dp[5009][5009];

int get(int i, int j)
{
	if (i >= j)
		return 0;

	if (dp[i][j] != 0)
		return dp[i][j];

	if (str[i] == str[j])
		return dp[i][j] = get(i + 1, j - 1);

	return dp[i][j] = min(get(i + 1, j), get(i, j - 1)) + 1;
}

int main()
{
	scanf("%d\n", &n);
	gets(str);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			dp[i][j] = 0;
	printf("%d", get(0, n - 1));
	system("pause");
	return 0;
}